<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>YK Value-added System</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/admin.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>css/common.css" />
	<script src="<%=basePath%>js/sys/validate.js" type="text/javascript"></script>
	<script src="<%=basePath%>js/json.js" type="text/javascript"></script>
	<script src="<%=basePath%>js/prototype.js" type="text/javascript"></script>
	<script type="text/javascript" charset="utf-8" defer="defer" src="<%=basePath%>js/wdatepicker/WdatePicker.js"></script>
	<script type="text/javascript">
		var judgment;
		function check(){
			if(document.getElementById("name").value==""){
				alert("项目名称不能为空！");
				document.getElementById("name").focus();
				return false ;
			}
			var judgment;
			var name=encodeURIComponent(document.getElementById("name").value);
			var id=document.getElementById("id").value;
			var url ="<%=basePath%>admin/system/menu/menu!checkMenuByName.action?name="+name+"&id="+id;
	        new Ajax.Request(url,{method:'post',asynchronous:false,
	           	onComplete:function(json){
	           	judgment=json.responseText.parseJSON().judgment;
			    if(judgment=="0"){
			    	alert("该菜单名已经存在！");
			    }
	           }
	        });
	        if(judgment=="0"){
		        return false;
	        }else{
	         	return true;
	        }
		}
		
		function getMenuListByParentID() {
			var parent_id=document.getElementById("parent_id").value;
           	var url = "<%=basePath%>admin/system/menu/menu!getMenuListByParentID.action?parent_id="+parent_id;
           	new Ajax.Request(url,{method:'post',onComplete:toMenuList});
        }
        function toMenuList(json){
        	var submenuList=json.responseText.parseJSON().submenuList;
        	var submenus=submenuList.split(";");
        	var objs=document.getElementById("sort").options;
        	objs.length=0;
        	objs.add(new Option("--请选择--",""));
        	for(var i=0;i<submenus.length;i++){
        		var m=submenus[i].split(":");
        		var obj=new Option(m[1],m[0]);
        		objs.add(obj);
        	}
        	
        }
	</script>
  </head>
  
  <body>
<table width="95%" border="0" align="center" cellspacing="0">
  <tr>
    <td height="30"><table width="100%" border="0">
      <tr>
        <td width="30"><img src="images/location_left.gif" width="24" height="30" /></td>
        <td>
        	您当前的位置是：菜单管理 -&gt;修改菜单<br>
        </td>
      </tr>
      <tr>
          <td colspan="2"><hr width="80%" align="left"></td>
		</tr>
    </table></td>
  </tr>
  <tr>
    <td><form id="form1" name="form1" method="post" action="<%=basePath%>admin/system/menu/menu!editMenu.action" onsubmit="return check();">
      <table width="100%" border="0" cellspacing="3">
      <tr>
          <td><font color="red" style="font-size:12px;"></font></td>
         <td>
          <font color="red" style="font-size:12px;"><s:actionmessage/><s:actionerror/></font>
          </td>
		</tr>
		<tr>
          <td align="right">
          	<span class="style">*</span>菜单名称：
          </td>
          <td colspan="3">
          	<input type="text" style="width:700px" id="name" name="name" value="${menu.name}" maxlength="50"
          		onfocus="currentBackgroundColor=this.style.backgroundColor;this.style.background='#FFFF99';" 
				onblur="this.style.backgroundColor=currentBackgroundColor;" style="height: 25px;"/>   
          </td>
        </tr>
        <tr>
          <td align="right">
          	菜单url：
          </td>
          <td colspan="3">
          	<input type="text" style="width:700px" id="url" name="url" value="${menu.url}" maxlength="200"
          		onfocus="currentBackgroundColor=this.style.backgroundColor;this.style.background='#FFFF99';" 
				onblur="this.style.backgroundColor=currentBackgroundColor;" style="height: 25px;"/>   
			<input type="hidden" id="id" name="id" value="${menu.id}"/>
			<input type="hidden" id="oldSort" name="oldSort" value="${menu.sort}"/>
			<input type="hidden" id="oldParent_id" name="oldParent_id" value="${menu.parent_id}"/>
			<input type="hidden" id="beforeSort" name="beforeSort" value="${beforeMenu.sort}"/>
          </td>
        </tr>
        <tr>
          <td width="5%" align="right">
          	模块id：
          </td>
          <td width="15%">
          	<select id="module_id" name="module_id">
          		<option value="">--请选择--</option>
          		<s:iterator value="moduleList" id="module">
          			<option value="${module.module_id}" <s:if test="menu.module_id==module.module_id">selected="selected"</s:if>>${module.module_name}</option>
          		</s:iterator>
         	</select>
          </td>
          <td width="5%" align="right">
          	<span class="style">*</span>是否可用：
          </td>
          <td width="15%">
				<input type="radio" name="active" id="active" value="Y" <c:if test="${menu.active=='Y'}">checked</c:if> />可用
		   		<input type="radio" name="active" id="active" value="N" <c:if test="${menu.active=='N'}">checked</c:if> />不可用
          </td>
        </tr>
        
        <tr>
          <td width="5%" align="right">
          	对应父菜单：
          </td>
          <td width="15%">
          	<select id="parent_id" name="parent_id" onchange="getMenuListByParentID();">
          		<option value="">--请选择--</option>
          		<s:iterator value="menuList" id="menu1">
          			<option value="${menu1.parent_id}" <c:if test="${menu.parent_id==menu1.parent_id}">selected="selected"</c:if>>${menu1.name}</option>
          		</s:iterator>
         	</select>
          </td>
          <td width="5%" align="right">
          	位置：
          </td>
          <td width="15%">
          	<select id="sort" name="sort">
          		<option value="">--请选择--</option>
          		<s:iterator value="sortMenuList" id="menu2">
          			<option value="${menu2.sort}" <c:if test="${beforeMenu.sort==menu2.sort}">selected="selected"</c:if>>${menu2.name}</option>
          		</s:iterator>
         	</select>之后
          </td>
        </tr>
		<tr>
          <td colspan="4"><hr width="80%" align="left"></td>
		</tr>
        <tr>
          <td align="right"><input type="submit" name="Submit" value="修改" class="Button" /></td>
          <td><input type="button" name="Submit22" value="返回" class="Button"  onclick="history.back();"/></td>
        </tr>
      </table>
        </form>
    </td>
  </tr>
</table>
</body>
</html>